<template>
  <el-table :data="asisList" stripe style="width: 100%">
    <el-table-column prop="atitle" label="标题" #default="scope">
      <el-link @click="toDetail(scope.row.aid)">{{ scope.row.atitle }}</el-link>
    </el-table-column>
    <el-table-column prop="asubhead" label="副标题" width="180"/>
    <el-table-column prop="createdate" width="180" label="发布时间"/>
    <el-table-column prop="astatus" label="状态" #default="scope">
      <!--      1：等待审核，2：正在筹集，3：筹集结束，4：已经提现，5：审核为通过-->
      {{
        scope.row.astatus === 1 ? '等待审核' : scope.row.astatus === 2 ? '正在筹集' : scope.row.astatus === 3 ? '筹集结束' : scope.row.astatus === 4 ?
            '已经提现' : scope.row.astatus === 5 ? '审核未通过' : '其他'
      }}
    </el-table-column>
    <el-table-column prop="aneedmoney" label="目标金额"/>
    <el-table-column prop="anowmoney" label="已筹金额"/>
    <el-table-column fixed="right" label="操作" width="120">
      <template #default="scope">
        <el-button @click="aheadEnd(scope.row.aid)" v-if="scope.row.astatus===2" type="primary" size="small"
                   round>提前结束
        </el-button>
        <el-button @click="withdraw(scope.row)" v-if="scope.row.astatus===3" type="success" size="small"
                   round>提现
        </el-button>
      </template>
    </el-table-column>
  </el-table>
  <!--  分页-->
  <div class="pageBox">
    <el-pagination
        :page-size="5"
        small
        background
        layout="prev, pager, next"
        :total="total"
        class="mt-4"
        v-model:current-page="nowPage"
        @update:current-page="getData"
    />
  </div>  <!--  银行卡信息弹框-->
  <el-dialog
      v-model="dialogVisible"
      title="输入账户信息"
      width="30%"
  >
    <el-form
        label-position="right"
        label-width="100px"
        :model="tempAssis"
        style="max-width: 460px"
    >
      <el-form-item label="银行卡号：">
        <el-input v-model="tempAssis.acardid" style="width: 230px"></el-input>
      </el-form-item>
      <el-form-item label="开户姓名：">
        <el-input v-model="tempAssis.acardname" style="width: 230px"></el-input>
      </el-form-item>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="dialogVisible = false">取消</el-button>
        <el-button type="primary" @click="submit">
          确定
        </el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script>
import doThis from "@/api/getData";
import {ElMessage} from "element-plus";

export default {
  name: "UserAss",
  data() {
    return {
      asisList: [],
      tempAssis: {},
      nowPage: 1,
      total: 0,
      dialogVisible: false,
      acardid: '',
      acardname: '',
    }
  },
  methods: {
    aheadEnd(aid) {
      doThis.doGet("/asstance/change", {aid: aid, astatus: 3}).then(res => {
/*        if (res.code !== "0") {
          alert(res.msg)
        } else {
          this.getData()
        }*/
        if (res.code === "0") {
          this.getData()
        }else {
          ElMessage.error(res.msg)
        }
      })
    },
    withdraw(assis) {
      this.tempAssis = assis
      this.dialogVisible = true

    },
    submit(){

      this.tempAssis.astatus = 4
      doThis.doGet("/asstance/updateCard", this.tempAssis).then(res => {
        if (res.code !== "0") {
          // alert(res.msg)
          ElMessage.error(res.msg)
        } else {
          this.tempAssis = {}
          this.getData()
          this.dialogVisible = false
        }
      })
    },
    getData() {
      doThis.doGet("/asstance/finByUser", {pageNum: this.nowPage}).then(res => {
        console.log(res)
        this.asisList = res.data.list
        this.total = res.data.count
      })
    },
    toDetail(aid){
      this.$router.push("/front/assindex/asstanceDetail/"+aid)
    }
  },

  created() {
    this.getData()
  }

}
</script>

<style>

</style>